www.gusucode.com > Deep Sudoku Solver工具箱matlab源码程序 > Deep Sudoku Solver/src/sudoku/+sudoku/+synth/addPrintedDigit.m

    function im = addPrintedDigit(im, digit, minSize, maxColour, border, maxOffset)
% Copyright 2018 The MathWorks, Inc.
    
    possibleFonts = {'Arial', ...
                        'Garamond', ...
                        'Courier New', ...
                        'Gill Sans MT', ...
                        'Comic Sans MS', ...
                        'Calibri', ...
                        'Tahoma', ...
                        'Times New Roman', ...
                        'Times New Roman Bold', ... 
                        'Times New Roman Italic', ...
                        'Verdana', ...
                        'Verdana Bold'};
    font = possibleFonts{randi(numel(possibleFonts))};
    resolution = size(im, 1);
    maxSize = resolution - 2*border;
    fontSize = round((maxSize - minSize)*rand(1) + minSize);

    textColour = maxColour*rand(1, 3);
    position = [resolution/2, resolution/2] + maxOffset.*(rand(1, 2) - 0.5);

    im = insertText(im, position, digit, ...
                    'BoxOpacity', 0, ...
                    'Font', font, ...
                    'FontSize', fontSize, ...
                    'TextColor', textColour, ...
                    'AnchorPoint', 'center');
    clear insertText % Avoid a strange memory issue
end